//
//  BaseTableViewController.swift
//  SinaWeiBo
//
//  Created by gxiangzi on 15/8/31.
//  Copyright © 2015年 hqu. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController {
    
    var userLogon = UserAccountViewModel.sharedUserAccount.userLogon

    // 不使用懒加载的方式，优化内存，当登陆之后，visitor 就不存在
    var visitor:VisitorLoginView?

    override func viewDidLoad() {
        super.viewDidLoad()
        
        visitor?.loginButton.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)
        visitor?.registerButton.addTarget(self, action: "register", forControlEvents: UIControlEvents.TouchUpInside)
        
        
    }
    
    override func loadView() {
        
        userLogon ? super.loadView() : setUpVisitorView()
    }
    
     // MARK: - 替换跟视图的界面
    private func setUpVisitorView() {
        
        visitor = VisitorLoginView()
        view = visitor
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self , action: "register")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self , action: "login")
  
    }
    
    
     // MARK: - 注册 & 登陆事件方法
    @objc private func login() {
        
        let oauthVC = UINavigationController(rootViewController: OauthViewController())
        navigationController?.presentViewController(oauthVC, animated: true, completion: nil)
        
    }
    
    @objc private func register() {
        print("注册")
    }
}
